const util = require('../../utils/util.js');

Page({
  data: {
    tabIndex: 0,
    tabs: ['专业知识', '中医养生', '能力提升', '店务管理', '快乐生活', '其他'],
    bannerlist: [],
    hotteacherlist: [],
    willlesson: [],
    lessonlist: [],
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    currentTab: '0',
    lessoninfo: {},
    lessonid: 0
  },
  onLoad: function() {
    this.getindexinfo();
    this.getindexlessonlist();
  },
  onShow: function() {
    this.getindexinfo();
    this.getindexlessonlist();
    wx.showShareMenu({
      withShareTicket: true
    })
  },
  getindexinfo: function() {
    let that = this;
    util.request('index/getindexinfo').then(function(res) {
      //console.log(res.data.bannerlist);
      if (res.errno === 0) {
        that.setData({
          bannerlist: res.data.bannerlist,
          hotteacherlist: res.data.hotteacherlist,
          willlesson: res.data.willlesson
        });
      }
    });
  },
  getindexlessonlist: function() {
    let that = this;
    util.request('index/getindexlessonlist').then(function(res) {
      console.log(res.data);
      if (res.errno === 0) {
        that.setData({
          lessonlist: res.data.lessonlist,
        });
      }
    });
  },
  changeTab(e) {
    console.log(e.currentTarget.dataset.id)
    this.setData({
      tabIndex: e.currentTarget.dataset.id
    })
  },
  toSearch() {
    wx.navigateTo({
      url: '/pages/search/search'
    })
  },
  navigateClick(e) {
    console.log(e.currentTarget.dataset.url)
    wx.navigateTo({
      url: e.currentTarget.dataset.url
    })
  },
  boutiqueTo(e) {
    wx.navigateTo({
      url: '/pages/special/special'
    })
  },
  //**跳转进入常规课程页面 */
  toLessoninfo(e) {
    //console.log(e.currentTarget.dataset.id);
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/lessoninfo/lessoninfo?id=${id}`
    })
  },
  //**跳转进入直播课程 */
  toliveLessoninfo(e) {
    //console.log(e.currentTarget.dataset.id);
    let id = e.currentTarget.dataset.id;
    console.log(id);
    wx.navigateTo({
      url: `/pages/lessonliveinfo/lessonliveinfo?id=${id}`
    })
  },
  goClasslist(e) {
    let title = e.currentTarget.dataset.title;
    let classid = e.currentTarget.dataset.classid;
    wx.navigateTo({
      url: '/pages/classlist/classlist'
    })
  },
  bannerLesson(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/lessoninfo/lessoninfo?id=${id}`
    })
  },
  toteacherdetails(e) {
    let id = e.currentTarget.dataset.id;
    let schoolid = e.currentTarget.dataset.schoolid;
    if (id & schoolid) {
      wx.navigateTo({
        url: `/pages/teacherdetails/teacherdetails?id=${id}`
      })
    }
  },
  goteacherlist() {
    wx.navigateTo({
      url: `/pages/teacherlist/teacherlist`
    })
  },
  onShareAppMessage: function(res) {
    return {
      title: '小雅学院首页',
      path: 'pages/index/index',
      imageUrl:'http://p8pho5rm4.bkt.clouddn.com/sharelogo_new.png'
    }
  }
})